<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header">
	<title>用户注册</title>
	<meta name="keywords" content="用户注册">
</head>
<link th:href="@{/ajax/libs/iCheck/custom.css}" rel="stylesheet"/>
<link href="../../../static/css/login.min.css" th:href="@{css/login.min.css}" rel="stylesheet"/>

<body class="gray-bg" style="background-image: url('../../img/background.jpg');background-position: center;
background-size: cover">

    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>
                <h1 class="logo-name">TM</h1>
            </div>
            <h3 style="color: yellow;">欢迎注册 发展党员动态管理系统</h3>
            <form class="m-t" role="form" id="form-user-add" action="login.html">
<!--                 <div class="form-group">
                    <input type="text" class="form-control" placeholder="请输入用户名" name="loginName" id="loginName">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请输入邮箱" name="email" id="email">
                </div> -->
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请输入真实姓名" name="userName" id="userName">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请输入身份证号码" id="idCardNo" name="idCardNo">
                </div>
                <div class="form-group">
                    <select id="sex" class="form-control m-b" name="sex">
	                    <option value="0">男</option>
	                    <option value="1">女</option>
	                    <option value="2">未知</option>
	                </select>
                </div>  
                <div class="form-group">
                    <input type="password" class="form-control" placeholder="请输入密码" id="pwdNew" name="pwdNew">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" placeholder="请再次输入密码" id="confirm_password" name="confirm_password">
                </div>
                
                <div class="form-group">
                	<select class="select2 select2-college form-control" id="college" name="college">
                	</select>
                </div>
                <!-- <div class="form-group">
                	<select class="select2-major form-control" id="major" name="major">
                	</select>
                </div> -->

                <div class="form-group text-left">
                    <div class=" i-checks">
                        <label class="no-padding"   style="color: pink">
                            <input type="checkbox" id="agreement"><i></i> 我同意注册协议</label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary block full-width m-b">注 册</button>

                <p class="text-muted text-center" style="color: pink; font-size: 15px; font-weight: bold;" >已经有账户了？<a style="color: orange" href="login.html">点此登录</a></p>

            </form>
        </div>
    </div>
  
    
    <div th:include="include::footer"></div>
    <script>
    	var majors;//存储更新后的专业列表
    	var college = [{ id: 0, text: '请选择学院' }, { id: 1, text: '宝石与艺术设计' }, { id: 2, text: '外国语学院' }, { id: 3, text: '商学院' }, { id: 4, text: '机械与化工学院' }, { id: 5, text: '大数据与软件工程学院' }
    	, { id: 6, text: '电子与信息学院' }, { id: 7, text: '教师教育学院' }, { id: 8, text: '文学与传媒学院' }, { id: 9, text: '法学与公共管理学院' }, { id: 10, text: '马克思主义学院' }];

    	var $eventSelect2= $(".select2");
    	$(".select2-college").select2({
	        placeholder:"请选择学院啊",
	        language: "zh-CN",
	        data: college,
    	});
    	
    	//$(".select2-major").select2({
	    //    placeholder:"请选择学院啊",
	    //    language: "zh-CN",
	    //    data: [{id : 0, text : "请先选择学院"}]
    	//});
    	
    	/* $eventSelect2.on("select2:select", function (e) {
        var data = e.params.data;
        var id = data.id;
        //置空数组
        majors.length = 0;
		for(var i = 0; i < major.length; i++){
			if(major[i].id.toString().substr(0, 1) == id){
				console.log(major[i].id.toString().substr(0, 1));
				majors[i] = major[i];
			}
		}
		majors[0] = {id : 0, text : "请选择专业"};
		console.log(majors);
		getRegionList(majors, '.select2-major'); 
    });*/

    /* 根据所选，获取下一级的列表 */
    function getRegionList(value, clazz){
		$("#major").val();
		$('#major').empty();
        /* 生成新数据 */
        $("#major").select2({
            placeholder: "请选择专业洛",
            language: "zh-CN",
            data: value
        });
    }
    
    </script>
	<script>
        $("#form-user-add").validate({
        	rules:{
        		loginName:{
        			required:true,
        			minlength: 2,
        			maxlength: 10,
        			remote: {
                        url: ctx + "system/user/checkLoginNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.trim($("#loginName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            if (data == "0") return true;
                            else return false;
                        }
                    }
        		},
        		idCardNo:{
        			required: true,
        			isIdentity: true,
        			remote: {
                        url: ctx + "system/user/checkIdCardNoUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.trim($("#idCardNo").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            if (data == "0") return true;
                            else return false;
                        }
                    }
        		},
        		userName:{
        			required: true,
        			isName: true
        		},
        		pwdNew:{
        			required: true,
        			isPassword: true
        		},
        		confirm_password:{
        			required: true,
        			issame:true
        		}
        	},
			messages: {
				"loginName":{
					remote: "用户名已存在"
				},
		        "confirm_password": {
		            issame: "两次密码不一致"
		        },
		        "idCardNo":{
		        	remote: "身份证已存在"
		        }
		    },
    		showErrors: function(errorMap, errorList) {
	            this.defaultShowErrors();
	            for(var i = 0; i < errorList.length; i++) {
	        		$(errorList[i].element).one("blur", function() {
	                     $("label.error[for='" + (this.id ? this.id : this.name) + "']").remove();
	                });
	            }
        	},
        	submitHandler:function(form){
        		add();
        	}
        });
        
         function add() {
        	/* var loginName = $("input[name='loginName']").val(); */
        	var userName = $("input[name='userName']").val();
        	var password = $("input[name='pwdNew']").val();
        	var idCardNo = $("input[name='idCardNo']").val();
        	var sex = $("#sex option:selected").val();
        	var college = $('#college').val();
        	/* var major = $('#major').val(); */
        	//无选择学院则返回
        	if($('#college').val() == 0){
        		$.modal.msg("请选择学院");
        		return;
        	}
        	var agreement = $("input[type='checkbox']").is(':checked');
        	/* var email = $("input[name='email']").val(); */
        	if(!agreement){
        		$.modal.msg("请阅读协议后勾选同意");
        		return;
        	}

        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "system/user/register",
        		data : {
        			/* "loginName": loginName, */
        			"userName": userName,
        			"password": password,
        			"idCardNo": idCardNo,
        			"sex": sex,
        			"college": college,
        			/* "email": email */
        			/*"major": major */
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
					function delayer(){
					 window.location = "/";
					}
					jQuery(document).ready(function(){
					 setTimeout('delayer()', 5000);
					 //这里实现延迟5秒跳转
					});
        		}
        	});
        }
    </script>
  </body>
  
    <script>
        $(document).ready(function () {

        });
    </script>
</html>
